//
//  NoticeSetting.m
//  Notice
//
//  Created by CPX on 2018/9/28.
//

#import "NoticeSetting.h"

/**
 通知设置
 @author yzl
 */
@interface NoticeSetting ()

@property (nonatomic, copy) NSString *systemNoticePath;

@end

@implementation NoticeSetting

+ (instancetype)sharedSetting{
    static dispatch_once_t onceToken;
    static NoticeSetting *s = nil;
    dispatch_once(&onceToken, ^{
        s = [NoticeSetting new];
        [s _init];
    });
    return s;
}

- (void)_init{
    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    self.systemNoticePath = [docPath stringByAppendingString:@"/notice/"];
    [[NSFileManager defaultManager] createDirectoryAtPath:self.systemNoticePath withIntermediateDirectories:YES attributes:nil error:nil];
    
    self.readSystemNotis = [NSKeyedUnarchiver unarchiveObjectWithFile:[self.systemNoticePath stringByAppendingString:@"sysnotis"]];
    if (!self.readSystemNotis) {
        self.readSystemNotis = [NSMutableDictionary dictionaryWithCapacity:4];
    }
}

- (void)addSystemNotice:(NSInteger)notice{
    [self.readSystemNotis setObject:@(YES) forKey:@(notice)];
    
    [NSKeyedArchiver archiveRootObject:self.readSystemNotis toFile:[self.systemNoticePath stringByAppendingString:@"sysnotis"]];
}

@end
